//
//  CZD_DetailHeadView.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/9/27.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "CZD_DetailHeadView.h"

@interface CZD_DetailHeadView ()

@property (nonatomic, strong) UILabel *companyLab;
@property (nonatomic, strong) UIButton *phoneBtn;
@property (nonatomic, strong) UILabel *NOTitleLab;
@property (nonatomic, strong) UILabel *NOLab;
@property (nonatomic, strong) UILabel *heTongTitleLab;
@property (nonatomic, strong) UILabel *heTongLab;
@property (nonatomic, strong) UILabel *priceTitleLab;
@property (nonatomic, strong) UILabel *priceLab;
@property (nonatomic, strong) UIButton *supplierTypeBtn;

@end

@implementation CZD_DetailHeadView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = HexColor(0xffffff);
        self.companyLab = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, ScreenW - 30 - 30 - 15, 19)];
        self.companyLab.font = BoldFontOfSize(18);
        self.companyLab.textColor = HexColor(0x2B2C44);
        [self addSubview:self.companyLab];
        
        self.phoneBtn = [UIButton new];
        self.phoneBtn.nim_width = 30;
        self.phoneBtn.nim_height = 30;
        self.phoneBtn.nim_left = ScreenW - 15 - 30;
        self.phoneBtn.nim_centerY = self.companyLab.nim_centerY;
        [self.phoneBtn setImage:[UIImage imageNamed:@"icon_phone_click"] forState:0];
        [self.phoneBtn addTarget:self action:@selector(phoneClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.phoneBtn];
        
        self.NOTitleLab = [UILabel new];
        self.NOTitleLab.font = [UIFont systemFontOfSize:14];
        self.NOTitleLab.textColor = HexColor(0x9C9DB3);
        self.NOTitleLab.text = @"操作单号：";
        [self.NOTitleLab sizeToFit];
        self.NOTitleLab.nim_left = self.companyLab.nim_left;
        self.NOTitleLab.nim_top = self.companyLab.nim_bottom + 10;
        [self addSubview:self.NOTitleLab];
        
        self.NOLab = [[UILabel alloc] initWithFrame:CGRectMake(self.NOTitleLab.nim_right, self.NOTitleLab.nim_top, ScreenW - 15 - self.NOTitleLab.nim_right, self.NOTitleLab.nim_height)];
        self.NOLab.textColor = HexColor(0x2B2C44);
        self.NOLab.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.NOLab];
        
        self.heTongTitleLab = [UILabel new];
        self.heTongTitleLab.font = [UIFont systemFontOfSize:14];
        self.heTongTitleLab.textColor = HexColor(0x9C9DB3);
        self.heTongTitleLab.text = @"合同编号：";
        [self.heTongTitleLab sizeToFit];
        self.heTongTitleLab.nim_left = self.companyLab.nim_left;
        self.heTongTitleLab.nim_top = self.NOTitleLab.nim_bottom + 5;
        [self addSubview:self.heTongTitleLab];
        
        self.heTongLab = [[UILabel alloc] initWithFrame:CGRectMake(self.heTongTitleLab.nim_right, self.heTongTitleLab.nim_top, ScreenW - 15 - self.heTongTitleLab.nim_right, self.heTongTitleLab.nim_height)];
        self.heTongLab.textColor = HexColor(0x2B2C44);
        self.heTongLab.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.heTongLab];
        
        self.priceTitleLab = [UILabel new];
        self.priceTitleLab.font = [UIFont systemFontOfSize:14];
        self.priceTitleLab.textColor = HexColor(0x9C9DB3);
        self.priceTitleLab.text = @"参考价格：";
        [self.priceTitleLab sizeToFit];
        self.priceTitleLab.nim_left = self.companyLab.nim_left;
        self.priceTitleLab.nim_top = self.heTongTitleLab.nim_bottom + 5;
        [self addSubview:self.priceTitleLab];
        
        self.priceLab = [[UILabel alloc] initWithFrame:CGRectMake(self.priceTitleLab.nim_right, self.priceTitleLab.nim_top, ScreenW - 15 - self.priceTitleLab.nim_right, self.priceTitleLab.nim_height)];
        self.priceLab.textColor = HexColor(0x2B2C44);
        self.priceLab.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.priceLab];
        
        self.supplierTypeBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenW - 15 - 84, self.priceLab.nim_bottom - 25, 84, 25)];
        self.supplierTypeBtn.backgroundColor = Color_ThemeColor;
        self.supplierTypeBtn.layer.masksToBounds = YES;
        self.supplierTypeBtn.layer.cornerRadius = 4;
        [self.supplierTypeBtn setTitleColor:HexColor(0xffffff) forState:0];
        self.supplierTypeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:self.supplierTypeBtn];
        
        self.height = self.priceTitleLab.nim_bottom + 15;
    }
    return self;
}

- (void)phoneClick {
    NSString *str = [[NSMutableString alloc] initWithFormat:@"tel:%@",self.model.tlogistics_mobile];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str] options:@{} completionHandler:nil];
}

-(void)setModel:(CaoZuoDanMainModel *)model {
    _model = model;
    self.companyLab.text = model.tlogistics_name;
    self.NOLab.text = model.operating_num;
    self.heTongLab.text = model.constract_sn;
    self.priceLab.text = [NSString stringWithFormat:@"%@元",model.price];
    if (model.type == CaoZuoDanSupplierTypeTiHuo) {
        [self.supplierTypeBtn setTitle:@"提货供应商" forState:0];
    }else if (model.type == CaoZuoDanSupplierTypeGanXian) {
        [self.supplierTypeBtn setTitle:@"干线供应商" forState:0];
    }else if (model.type == CaoZuoDanSupplierTypePaiSong) {
        [self.supplierTypeBtn setTitle:@"派送供应商" forState:0];
    }else if (model.type == CaoZuoDanSupplierTypeJiaoHuo) {
        [self.supplierTypeBtn setTitle:@"交货供应商" forState:0];
    }else {
        [self.supplierTypeBtn setTitle:@"其他供应商" forState:0];
    }
}

@end
